import models from '../../../models'

export default defineEventHandler(async (event: any) => {
  try {
    const body = await readBody(event)
    
    const organization = await models.Organization.create(body, {
      include: [
        {
          model: models.Region,
          attributes: ['name', 'code']
        },
        {
          model: models.Organization,
          as: 'parent'
        }
      ]
    })
    
    return {
      success: true,
      organization
    }
  } catch (error) {
    throw createError({
      statusCode: 500,
      message: '创建组织失败'
    })
  }
}) 